
import Axios from "axios";

const token = ""

const myAxios = Axios.create({
  timeout: 180000, // 请求超时时间
});


// 请求拦截器
myAxios.interceptors.request.use(
  request => {
    // request.headers.common['Authorization'] = 'Bearer ' + token;
    // request.headers.common['Access-Control-Allow-Origin'] = "*";
    // request.headers.common['Access-Control-Allow-Credentials'] = 'true';
    return request;
  },
  error => {
    return Promise.reject(error);
  }
);

// 响应拦截器
myAxios.interceptors.response.use(
  response => {
    // console.log(response, 222222222)
    return response.data;
  },
  error => {
    return Promise.reject(error);
  }
);

const http = {
  async get(url, params) {
    return await myAxios({
      url: `http://localhost:3333/api/${url}`,
      method: "GET",
      ...params
    });
  },
  async post(url, data) {
    return await myAxios({
      url: `http://localhost:3333/api/${url}`,
      method: "POST",
      data
    });
  }
};

export default http;
